<template>
	<view class="my-promotion">
		<!--<view class="header">
			<view class="name acea-row row-center-wrapper">
				<view>当前佣金<text class='iconfont icon-wenhao1'></text></view>
			</view>
			<view class='num'>{{spreadInfo.commission || 0}}</view>
			 <view class='profit acea-row row-between-wrapper'>
				<view class='item'>
					<view>昨日收益</view>
					<view class='money'>{{spreadInfo.lastDayCount ? Number(spreadInfo.lastDayCount).toFixed(2) : 0}}
					</view>
				</view>
			</view> 
		</view>-->
		<view class='headerBox'>
			<p class='name'>当前佣金（元）</p>
			<p class='money'>￥<text class='num'>{{spreadInfo.commission || 0}}</text></p>
			<view @click="openSubscribe()" class='txBnt'>立即提现</view>
		</view>
		<view class="title">
			提现记录
			<p class="bottomXian"></p>
		</view>
		<view class='commission-details'>
			<view class='sign-record'>
				<block>
					<view class='list pad30'>
						<view class='item'>
							<!-- <view class='data'>提现记录</view> -->
							<view class='listn borRadius14'>
								<block  v-for="(item,index) in recordList" :key="index">
									<view class='itemn acea-row row-between-wrapper' style="height: 146rpx;">
										<view>
											<!-- <view class='name line1'>昵称：{{item.msqUser.nickname}}</view>
											<view class='name line1'>uid：{{item.msqUser.uid}}</view> -->
											<view class='name line1'>申请提现转出</view>
											<view>{{item.createTime}}</view>
										</view>
										<view class='num font-color' v-if="item.status == 1">+{{item.money}}
										</view>
										<view class='num' v-else>-{{item.money}}</view>
									</view>
								</block>
							</view>
						</view>
					</view>
				</block>
				<view v-if="recordList.length <1">
					<emptyPage title='暂无提现记录~'></emptyPage>
				</view>
			</view>
		</view>
		<!-- 规则弹窗 -->
		<uni-popup ref="popup" type="center" :maskClick="true">
			<view class="moneyBox">
				<p class="title">提现金额</p>
				<view class='list'>
					<view class='name'>￥</view>
					<input class='input' v-model="withdrawalMoney" placeholder='请输入提现金额' name="name"></input>
					<p class="all" @click="allMoney">全部提现</p>
				</view>
				<p class="xian"></p>
				<button class='moneyBoxBnt' @click="postProcessAdd">提现</button>
				<p style="color: #999;">请注意：提现需收取<span>{{withdrawalCommission}}</span>%手续费</p>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getInfo,
		processAdd,
		getUserInfo
	} from '@/api/user.js';
	import {
		getWithdrawalList,
		getDistributionConfig
	} from '@/api/xing.js';
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				spreadInfo: {},
				userInfo: {},
				withdrawalMoney: '',
				recordList: [],
				pageNum: 1,
				pageSize: 10,
				withdrawalCommission:''
			};
		},
		onLoad() {
			this.getSpreadInfo();
			this.getList();
			this.getDistribution()
		},
		methods: {
			getDistribution(){
				getDistributionConfig().then(res=>{
					this.withdrawalCommission=res.data.records[0].withdrawalCommission
				})
			},
			allMoney() {
				this.withdrawalMoney = this.spreadInfo.commission
			},
			getList() {
				let that = this;
				getWithdrawalList({
					pageNum: that.pageNum,
					pageSize: that.pageSize,
					beginDate: null,
					endDate: null
				}).then(res => {
					that.recordList = res.rows
					console.log(that.recordList, "that.recordList")
					that.pageNum = that.pageNum + 1;
				});
			},
			onReachBottomn() {
				this.getList();
			},
			getSpreadInfo() {
				getUserInfo().then(res => {
					this.userInfo = res.data
					getInfo().then(res => {
						this.spreadInfo = res.data;
					});
				})
			},
			openSubscribe() {
				this.$refs.popup.open();
			},
			postProcessAdd() {
				console.log(this.withdrawalMoney, "withdrawalMoney")
				// 校验提现金额是否为空
				if (!this.withdrawalMoney) {
					uni.showToast({
						title: '请输入提现金额',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				console.log(this.userInfo, "this.userInfo")
				// 调用 processAdd 接口，传入提现金额
				processAdd({
					uid: this.userInfo.uid,
					withdrawalMoney: this.withdrawalMoney
				}).then(res => {
					// 处理成功回调
					uni.showToast({
						title: '提现申请已提交，请等待处理',
						icon: 'none',
						duration: 2000
					});
					// 关闭弹窗
					this.$refs.popup.close();
					this.getSpreadInfo();
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.headerBox {
		width: 95%;
		height: 214rpx;
		background: linear-gradient(93deg, #639DFF 0%, #498CFF 100%);
		border-radius: 20rpx;
		color: #FFFFFF;
		margin: 20rpx;
		padding: 40rpx;
	
		.name {
			font-weight: 400;
			font-size: 30rpx;
			line-height: 71rpx;
		}
	
		.money {
			font-weight: bold;
			font-size: 50rpx;
			line-height: 7r1px;
		}
		.txBnt{
			float: right;
			margin-top: -90rpx;
			width: 158rpx;
			height: 55rpx;
			background: #82B2FD;
			border-radius: 27px;
			font-weight: bold;
			font-size: 26rpx;
			color: #FFFFFF;
			line-height: 55rpx;
			text-align: center;
		}
	}
	
	.title {
		font-weight: bold;
		font-size: 34rpx;
		color: #4776F8;
		line-height: 70rpx;
		margin-left: 20rpx;
		.bottomXian{
			width: 52rpx;
			height: 6rpx;
			background: #4776F8;
			border-radius: 10rpx;
			margin-left: 40rpx;
		}
	}
	
	.fold {
		width: 160rpx;
		height: 58rpx;
		float: right;
		background-color: #fff;
		line-height: 58rpx;
		border-radius: 24rpx;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		text-align: center;
		margin: -70rpx 20rpx 0rpx 0rpx;
	}
	.commission-details .promoterHeader .headerCon .money {
		font-size: 36rpx;
	}

	.commission-details .promoterHeader .headerCon .money .num {
		font-family: 'Guildford Pro';
	}

	.my-promotion .header {
		// background-image: url('http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/extensionBackground.png');
		// background-repeat: no-repeat;
		// background-size: 100% 100%;
		background: linear-gradient(to right, #639DFF, #498CFF);
		width: 100%;
		height: 295rpx;
	}

	.my-promotion .header .name {
		font-size: 30rpx;
		color: #fff;
		padding-top: 57rpx;
	}

	.my-promotion .header .num {
		text-align: center;
		color: #fff;
		margin-top: 28rpx;
		font-size: 90rpx;
		font-family: 'Guildford Pro';
	}

	.my-promotion .header .profit {
		padding: 0 20rpx;
		margin-top: 35rpx;
		font-size: 24rpx;
		color: rgba(255, 255, 255, 0.8);
	}

	.my-promotion .header .profit .item {
		min-width: 200rpx;
		text-align: center;
	}

	.my-promotion .header .profit .item .money {
		font-size: 34rpx;
		color: #fff;
		margin-top: 5rpx;
	}

	.my-promotion .bnt {
		font-size: 28rpx;
		color: #fff;
		width: 258rpx;
		height: 68rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 58rpx;
		margin: -36rpx auto 0 auto;
		background-color: #085CD6 !important;
		border: 4rpx solid #fff;
	}

	.moneyBox {
		width: 700rpx;
		height: 349rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 9rpx 1rpx rgba(0, 0, 0, 0.03);
		border-radius: 10rpx;
		padding: 19rpx 35rpx;
		margin: 10rpx 22rpx;

		.title {
			font-weight: 400;
			font-size: 30rpx;
			color: #333333;
			line-height: 71rpx;
		}

		.list {
			display: flex;
			justify-content: flex-start;
			flex-wrap: nowrap;

			.name {
				width: 69rpx;
				height: 100rpx;
				font-weight: bold;
				font-size: 60rpx;
				color: #333333;
				line-height: 100rpx;
			}

			.input {
				width: 430rpx;
				height: 100rpx;
				font-weight: 400;
				font-size: 30rpx;
				line-height: 100rpx;
			}

			.all {
				width: 103rpx;
				height: 100rpx;
				font-weight: 400;
				font-size: 26rpx;
				color: #085CD6;
				line-height: 100rpx;
			}

		}

		.xian {
			height: 1rpx;
			background: #E3E3E3;
		}

		.moneyBoxBnt {
			font-size: 28rpx;
			color: #fff;
			width: 258rpx;
			height: 68rpx;
			border-radius: 50rpx;
			text-align: center;
			line-height: 58rpx;
			background-color: #085CD6 !important;
			border: 4rpx solid #fff;
			margin: 20rpx auto;
		}
	}
</style>